package com.example.studentgrades.controller;

import com.example.studentgrades.entity.Student;
import com.example.studentgrades.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/listAll")
    public ResponseEntity<List<Student>> listAllStudents() {
        List<Student> students = studentService.findAll();
        return ResponseEntity.ok(students);
    }

    @GetMapping("/getById/{studentId}")
    public ResponseEntity<Student> getStudentById(@PathVariable Integer studentId) {
        Student student = studentService.findById(studentId);
        return ResponseEntity.ok(student);
    }

    @PostMapping("/add")
    public ResponseEntity<Void> addStudent(@RequestBody Student student) {
        studentService.save(student);
        return ResponseEntity.ok().build();
    }
}
